<?php

namespace app\api\model\user;

use app\api\model\BaseModel;

class UserAssetsModel extends BaseModel
{
    protected $name = 'user_assets';

    public function registerSuccess($user_id)
    {
        $usdt = config('site.give_money');
        if (empty($usdt)) $usdt = 0;

        $this->save([
            'user_id' => $user_id,
            'usdt' => $usdt
        ]);

        return true;
    }

    /**
     * Notes: 邀请用户奖励
     * User: 浪子膏
     * Date: 2023/10/22 10:09
     * @param $user_id
     * @param $money
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function addAssets($user_id, $money): bool
    {
        $info = $this->where('user_id', $user_id)->find();
        if (empty($info)) {
            return false;
        }
        $info->usdt = bcadd($money, $info->usdt, 10);
        $info->save();

        return true;
    }
}